import requests
# from scripts import Token

uat = "http://uat-ulm-sale-admin.jsunet.cn/backend/"


class UserTest(object):
    # 查询用户列表
    @staticmethod
    def get_list(data_list):
        url = uat + "admin/members"
        headers = {"Authorization": "eyJhbGciOiJIUzUxMiJ9.eyJ1aWQiOjE2NDEzNDIyODg4MzIwODYwMTcsInN1YiI6InVzZXIiLCJmb3VuZGVyIjpudWxsLCJyb2xlcyI6WyJTVVBFUl9BRE1JTiJdLCJleHAiOjE2ODMwODEwMjEsInV1aWQiOm51bGwsInVzZXJuYW1lIjoieWFuZ21pbmdtaW5nIn0.r4sE1M5TR2OCd85DxjLuwNqpF8Bj6lfob49172HNcYiGxReu7gcfX431NZeFncWNXWYeggobDDnlMi2x6HaLnw"}
        resp = requests.get(url, headers=headers, params=data_list)
        return resp

    # 编辑用户信息
    @staticmethod
    def put_user(json_user):
        url = uat + "/admin/members"
        headers = {"Authorization": "eyJhbGciOiJIUzUxMiJ9.eyJ1aWQiOjE2NDEzNDIyODg4MzIwODYwMTcsInN1YiI6InVzZXIiLCJmb3VuZGVyIjpudWxsLCJyb2xlcyI6WyJTVVBFUl9BRE1JTiJdLCJleHAiOjE2ODMwODEwMjEsInV1aWQiOm51bGwsInVzZXJuYW1lIjoieWFuZ21pbmdtaW5nIn0.r4sE1M5TR2OCd85DxjLuwNqpF8Bj6lfob49172HNcYiGxReu7gcfX431NZeFncWNXWYeggobDDnlMi2x6HaLnw"}
        resp = requests.put(url, headers=headers, json=json_user)
        return resp

    # 查看用户详情
    @staticmethod
    def details(memberId):
        url = uat + f"/admin/members/{memberId}"
        headers = {"Authorization": "eyJhbGciOiJIUzUxMiJ9.eyJ1aWQiOjE2NDEzNDIyODg4MzIwODYwMTcsInN1YiI6InVzZXIiLCJmb3VuZGVyIjpudWxsLCJyb2xlcyI6WyJTVVBFUl9BRE1JTiJdLCJleHAiOjE2ODMwODEwMjEsInV1aWQiOm51bGwsInVzZXJuYW1lIjoieWFuZ21pbmdtaW5nIn0.r4sE1M5TR2OCd85DxjLuwNqpF8Bj6lfob49172HNcYiGxReu7gcfX431NZeFncWNXWYeggobDDnlMi2x6HaLnw"}
        resp = requests.get(url, headers=headers)
        return resp




# 优化代码
#
# import requests
#
# class UserTest:
#     BASE_URL = "http://uat-ulm-sale-admin.jsunet.cn/backend/"
#     AUTH_HEADER = {
#         "Authorization": "eyJhbGciOiJIUzUxMiJ9.eyJ1aWQiOjE2NDEzNDIyODg4MzIwODYwMTcsInN1YiI6InVzZXIiLCJmb3VuZGVyIjpudWxsLCJyb2xlcyI6WyJTVVBFUl9BRE1JTiJdLCJleHAiOjE2ODMwODEwMjEsInV1aWQiOm51bGwsInVzZXJuYW1lIjoieWFuZ21pbmdtaW5nIn0.r4sE1M5TR2OCd85DxjLuwNqpF8Bj6lfob49172HNcYiGxReu7gcfX431NZeFncWNXWYeggobDDnlMi2x6HaLnw"
#     }
#
#     @staticmethod
#     def _make_request(method, endpoint, **kwargs):
#         url = f"{UserTest.BASE_URL}{endpoint}"
#         try:
#             response = requests.request(method, url, headers=UserTest.AUTH_HEADER, **kwargs)
#             response.raise_for_status()  # 如果请求返回了错误状态码，则抛出异常
#             return response
#         except requests.RequestException as e:
#             print(f"请求失败: {e}")
#             return None
#
#     @staticmethod
#     def get_list(data_list):
#         return UserTest._make_request("GET", "admin/members", params=data_list)
#
#     @staticmethod
#     def put_user(json_user):
#         return UserTest._make_request("PUT", "admin/members", json=json_user)
#
#     @staticmethod
#     def details(memberId):
#         return UserTest._make_request("GET", f"admin/members/{memberId}")
#
# # 示例用法：
# # response = UserTest.get_list({"page": 1, "size": 10})
# # print(response.json())

